package com.ruoyi.broker.service.impl;

import com.ruoyi.broker.domain.Broker;
import com.ruoyi.broker.mapper.BrokerMapper;
import com.ruoyi.broker.service.IBrokerService;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.check.CheckEmptyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 经纪人数据Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-09
 */
@Service
public class BrokerServiceImpl implements IBrokerService {
    @Autowired
    private BrokerMapper brokerMapper;

    /**
     * 查询经纪人数据
     *
     * @param id 经纪人数据主键
     * @return 经纪人数据
     */
    @Override
    public Broker selectBrokerById(Long id) {
        return brokerMapper.selectBrokerById(id);
    }

    /**
     * 查询经纪人数据列表
     *
     * @param broker 经纪人数据
     * @return 经纪人数据
     */
    @Override
    public List<Broker> selectBrokerList(Broker broker) {
        return brokerMapper.selectBrokerList(broker);
    }

    /**
     * 新增经纪人数据
     *
     * @param broker 经纪人数据
     * @return 结果
     */
    @Override
    public int insertBroker(Broker broker) {
        broker.setCreateTime(DateUtils.getNowDate());
        return brokerMapper.insertBroker(broker);
    }

    /**
     * 修改经纪人数据
     *
     * @param broker 经纪人数据
     * @return 结果
     */
    @Override
    public int updateBroker(Broker broker) {
        broker.setUpdateTime(DateUtils.getNowDate());
        return brokerMapper.updateBroker(broker);
    }

    /**
     * 批量删除经纪人数据
     *
     * @param ids 需要删除的经纪人数据主键
     * @return 结果
     */
    @Override
    public int deleteBrokerByIds(Long[] ids) {
        if (!CheckEmptyUtil.isEmpty(ids)){
            for (Long id : ids) {
                Broker broker = brokerMapper.selectBrokerById(id);
                brokerMapper.updateTechnicianType(broker.getTid());
            }
        }
        return brokerMapper.deleteBrokerByIds(ids);
    }

    /**
     * 删除经纪人数据信息
     *
     * @param id 经纪人数据主键
     * @return 结果
     */
    @Override
    public int deleteBrokerById(Long id) {
        return brokerMapper.deleteBrokerById(id);
    }
}
